import json



from applications.models import BookInfo
from flask import Blueprint, request, jsonify


thebookInfo_bp = Blueprint('thebookInfo', __name__, url_prefix='/thebookInfo')

@thebookInfo_bp.get('/get_theBookInfo')
def get_theBookInfo():
    book_name = request.args.get("book_name")
    existing_book = BookInfo.query.filter_by(book_name=book_name).first()
    if existing_book:
        book_info = {
            "id": existing_book.id,
            "book_name": existing_book.book_name,
            "author": existing_book.author,
            "publisher": existing_book.publisher,
            "publish_time": existing_book.publish_time.strftime('%Y-%m-%d %H:%M:%S'),
            "isbn": existing_book.isbn,
            "book_type": existing_book.book_type,
            "borrow_status": existing_book.borrow_status
        }
        return json.dumps(book_info)

    return json.dumps({"message": "Book not found"})
